package com.nommon.menu;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;

import com.nommon.tool.Vector2D;

public class Airplane {

	private static final int SPPED = 100;
	private Point position;
	private Bitmap bitmap;
	private float roll;
	
	public Airplane(Bitmap bitmap) {
		position = new Point(300, 300);
		Matrix m = new Matrix();
		//m.postRotate(90, bitmap.getWidth()/2, bitmap.getHeight()/2);
		m.postScale(0.5f, 0.5f);
		this.bitmap = Bitmap.createBitmap(bitmap, 0, 0,
				bitmap.getWidth(), bitmap.getHeight(), m, true);
		roll = 1;
	}

	public void onUpdate(float deltaSec, Vector2D joystick) {
		roll = joystick.x();
//		android.util.Log.e("", ""+deltaSec);
		position.x += SPPED*deltaSec*joystick.x();
		position.y += SPPED*deltaSec*joystick.y();
	}

	public void draw(Canvas canvas) {
		Matrix m = new Matrix();
		m.postRotate(roll*8, bitmap.getWidth()/2, bitmap.getHeight()/2);
		m.postScale(1, -roll*roll/10 +1);
		m.postTranslate(position.x-bitmap.getWidth()/2, position.y-bitmap.getHeight()/2);
		canvas.drawBitmap(bitmap, m, null);
	}

}
